package com.fau.hm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.Hibernate;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 话务员任务考核
 * @author dangjh
 * @datetime 2014年10月30日,下午5:50:13
 */
@Entity
@Table(name = "medical_call_check")
public class MedicalCallCheck implements Serializable, JSONAware {

	private static final long serialVersionUID = 7156218080136128110L;

	private String id;
	private MedicalAdmin user;		//话务员Id
	private String status;			//处理状态
	private String taskId;			//任务id
	private String eid;				//企业id
	private Date createTime = new Date();//创建时间
	
	private Integer allTaskNum;		//任务总数
	private Integer deliveryNum;	//已发货数
	private String percentage;		//完成百分比
	private String name;			//用户名称
	private Date startTime;			//开始时间
	
	public MedicalCallCheck(){
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id")
	public MedicalAdmin getUser() {
		return user;
	}

	public void setUser(MedicalAdmin user) {
		this.user = user;
	}

	@Column(name = "status", length = 5)
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Column(name = "task_id", length = 32)
	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	@Column(name = "eid", length = 32)
	public String getEid() {
		return eid;
	}

	public void setEid(String eid) {
		this.eid = eid;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Transient
	public Integer getAllTaskNum() {
		return allTaskNum;
	}

	public void setAllTaskNum(Integer allTaskNum) {
		this.allTaskNum = allTaskNum;
	}
	
	@Transient
	public Integer getDeliveryNum() {
		return deliveryNum;
	}

	public void setDeliveryNum(Integer deliveryNum) {
		this.deliveryNum = deliveryNum;
	}

	@Transient
	public String getPercentage() {
		return percentage;
	}

	public void setPercentage(String percentage) {
		this.percentage = percentage;
	}
	
	@Transient
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@Transient
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("allTaskNum", allTaskNum);
		obj.put("deliveryNum", deliveryNum);
		obj.put("status", status);
		obj.put("name", user.getName());
		if(Hibernate.isInitialized(user.getGroup())) {
			obj.put("groupName", user.getGroup().getName());
			obj.put("platformName", user.getGroup().getPlatform().getName());
		}
		obj.put("percentage", percentage);
		obj.put("startTime", startTime);
		return obj.toJSONString();
	}

}
